package com.ruoyi.classification.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.classification.domain.CommodityProductClass;
import com.ruoyi.classification.service.ICommodityProductClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品分类Controller
 * 
 * @author kzc
 * @date 2024-03-09
 */
@RestController
@RequestMapping("/classification/classification")
public class CommodityProductClassController extends BaseController
{
    @Autowired
    private ICommodityProductClassService commodityProductClassService;

    /**
     * 查询商品分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CommodityProductClass commodityProductClass)
    {
        startPage();
        List<CommodityProductClass> list = commodityProductClassService.selectCommodityProductClassList(commodityProductClass);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommodityProductClass commodityProductClass)
    {
        List<CommodityProductClass> list = commodityProductClassService.selectCommodityProductClassList(commodityProductClass);
        ExcelUtil<CommodityProductClass> util = new ExcelUtil<CommodityProductClass>(CommodityProductClass.class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Integer categoryId)
    {
        return success(commodityProductClassService.selectCommodityProductClassByCategoryId(categoryId));
    }

    /**
     * 新增商品分类
     */
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommodityProductClass commodityProductClass)
    {
        return toAjax(commodityProductClassService.insertCommodityProductClass(commodityProductClass));
    }

    /**
     * 修改商品分类
     */
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommodityProductClass commodityProductClass)
    {
        return toAjax(commodityProductClassService.updateCommodityProductClass(commodityProductClass));
    }

    /**
     * 删除商品分类
     */
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Integer[] categoryIds)
    {
        return toAjax(commodityProductClassService.deleteCommodityProductClassByCategoryIds(categoryIds));
    }
}
